<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>房间列表</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="{$smarty.const.PUBLIC_PATH}css/amazeui.min.css">
    <script type="text/javascript" src="{$smarty.const.PUBLIC_PATH}js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="{$smarty.const.PUBLIC_PATH}js/amazeui.min.js"></script>
    <style>
        .am-badge{
            float: right;
            line-height:normal;
        }
        .am-img-thumbnail{
            width:40px;
        }
    </style>
</head>
<body>
    <ul class="am-list am-list-border">
        {foreach $rooms as $k=>$v}
        <li data-uid="{$v.uid}" data-href="{$smarty.const.__CONTROLLER__}/inroom/uid/{$v.uid}"><a><i class="am-icon-home am-icon-fw"></i>
            {$v.uid}
            {foreach $v['users'] as $kk=>$vv}
                <img src="{$vv.main_img}" alt="..." class="am-img-thumbnail am-radius">
            {/foreach}
            {if $v.is_playing}
                <span class="am-badge am-badge-danger">正在游戏</span>
            {else}
                <span class="am-badge am-badge-success">等待中</span>
            {/if}
        </a></li>
        {/foreach}
    </ul>
    <div style="text-align: center">
        <a class="am-btn am-btn-success" href="{$smarty.const.__CONTROLLER__}/createroom" >创建房间</a>
    </div>
</body>
<script>
    $(".am-list li").click(function () {
        thisli=$(this);
        $.post("{$smarty.const.__MODULE__}/Ajax/is_playing",{ uid:thisli.data("uid")},function (ret) {
            if(ret){
                alert("此房间已开始游戏！")
                window.location.reload()
            }else{
                // console.log(thisli.data("href"))
                window.location.href=thisli.data("href")
            }
            console.log(ret)
        })
    })
</script>
</html>